﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Common="http://imagin.tech/imagin/common"
    xmlns:Controls.Common="http://imagin.tech/imagin/controls/common">
    <Common:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>

    <ControlTemplate x:Key="ControlTemplate.CheckBox" TargetType="{x:Type CheckBox}">
        <BulletDecorator>
            <Grid Background="Transparent">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    ClipToBounds="False" 
                    Height="16"
                    VerticalAlignment="Center"
                    Width="16">
                    <Grid>
                        <Controls.Common:MaskedImage 
                            x:Name="PART_Tick" 
                            ImageColor="{DynamicResource Brush.CheckBox.Tick.Fill}"
                            Margin="0,-3,-3,0"
                            Source="pack://application:,,,/Imagin.Styles;component/Images/Tick.png"
                            Visibility="Collapsed" />
                        <Rectangle 
                            x:Name="PART_Indeterminate"
                            Fill="{DynamicResource Brush.CheckBox.Tick.Fill}"
                            Margin="2"
                            Visibility="Collapsed"/>
                    </Grid>
                </Border>
                <TextBlock 
                    Grid.Column="1" 
                    Margin="10,0,0,0" 
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    Visibility="{Binding Content, Mode=OneWay, Converter={StaticResource NullToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}">
                    <InlineUIContainer><ContentPresenter/></InlineUIContainer>
                </TextBlock>
            </Grid>
        </BulletDecorator>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="{x:Null}">
                <Setter TargetName="PART_Indeterminate" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="PART_Tick" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" Value="0.6" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type CheckBox}">
        <Setter Property="Background" Value="{DynamicResource Brush.CheckBox.Background}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.CheckBox.Border}" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="ClipToBounds" Value="False" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template" Value="{StaticResource ControlTemplate.CheckBox}"/>
    </Style>
</ResourceDictionary>